package com.mmall.controller.backend;


import com.mmall.common.Const;
import com.mmall.common.ServerResponse;
import com.mmall.pojo.User;
import com.mmall.service.IOrderService;
import com.mmall.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller("/manage/order/")
@Slf4j
public class ManageOrderController {

    @Autowired
    private IUserService iUserService;

    @Autowired
    private IOrderService iOrderService;


    @RequestMapping(value = "list.do",method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse list(HttpSession session,
                               @RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,
                               @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize){
        ServerResponse serverResponse = iUserService.checkAdminRole(session);
        if(!serverResponse.is_success()){
            return serverResponse;
        }
        return iOrderService.getOrderList(null,pageNum,pageSize);
    }

    @RequestMapping(value = "search.do",method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse search(HttpSession session,Long orderNo,
                                 @RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,
                                 @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize){
        ServerResponse serverResponse = iUserService.checkAdminRole(session);
        if(!serverResponse.is_success()){
            return serverResponse;
        }
        return iOrderService.manageSearch(orderNo,pageNum,pageSize);
    }

    @RequestMapping(value = "detail.do",method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse detail(HttpSession session,Long orderNo){
        ServerResponse serverResponse = iUserService.checkAdminRole(session);
        if(!serverResponse.is_success()){
            return serverResponse;
        }
        return iOrderService.getOrderDetail(null,orderNo);
    }

    @RequestMapping(value = "send_goods.do",method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse sendGoods(HttpSession session,Long orderNo){
        ServerResponse serverResponse = iUserService.checkAdminRole(session);
        if(!serverResponse.is_success()){
            return serverResponse;
        }
        return iOrderService.sendGoods(orderNo);
    }



}
